import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CustomButton extends StatelessWidget {
  /// 按钮宽度
  final double width;

  /// 按钮高度
  final double height;

  /// 文本
  final String text;

  /// 是否置灰
  final bool isAsh;

  /// 圆角，默认为54.0
  final double borderRadius = 54.0;

  /// 点击事件
  final VoidCallback? onPressed;

  /// 文本颜色
  final Color textColor;

  /// 背景颜色：支持单色、渐变色
  final List<Color> bgColorList;

  CustomButton({
    super.key,
    this.isAsh = true,
    required this.text,
    double? width,
    double? height,
    this.onPressed,
    this.textColor = Colors.white,
    this.bgColorList = const [Color(0xFF0A4EF1), Color(0xFF7AE0E7)],
  })  : width = width ?? 420.w,
        height = height ?? 90.h;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        if (!isAsh) {
          onPressed?.call();
        }
      },
      child: Opacity(
          opacity: isAsh ? 0.4 : 1,
          child: Container(
            width: width,
            height: height,
            alignment: Alignment.center,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(borderRadius),
                color: bgColorList.length == 1 ? bgColorList.first : null,
                gradient: bgColorList.length > 1
                    ? LinearGradient(
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                        colors: bgColorList)
                    : null),
            child: Text(
              text,
              style: TextStyle(
                fontSize: 32.sp,
                color: textColor,
              ),
            ),
          )),
    );
  }
}
